//
//  ViewController.m
//  record_plugin_demo
//
//  Created by zqj on 2024/8/20.
//



#import "ViewController.h"
#import "MBProgressHUD/MBProgressHUD.h"
#import <record_plugin/record_plugin.h>
#import <VideoToolbox/VideoToolbox.h>

#define baseUrl @"https://testqa-rly.dgzq.com.cn:1443"
#define testZqjImg @"https://testqa-rly.dgzq.com.cn:1443/ronglianyun/ronglianyun/pic/20240924/png/17271643933413bf5427d50f74d6fadbe6f819c2db03a.png"
#define testcfImg @"https://testqa-rly.dgzq.com.cn:1443/ronglianyun/ronglianyun/pic/20241105/png/1730790580860392c31c89e2a46fda365cfaf35ec64e8.png"

#define productcode @"YW_20240927_1"

//双向
#define productId @"2125"
#define phone1 @"15208436506"
#define customerName1 @"张启金"
#define checkScore 0.7
#define applyID @"202409251340176618"


@interface ViewController ()<RecordManagerDelegate>

@property (nonatomic,strong)MBProgressHUD *hud;
@property (weak, nonatomic) IBOutlet UITextField *serverUrlTf;
@property (weak, nonatomic) IBOutlet UITextField *codeTf;
@property (weak, nonatomic) IBOutlet UITextField *productIdTf;
@property (weak, nonatomic) IBOutlet UITextField *idCardTf;
@property (weak, nonatomic) IBOutlet UITextField *similarityTf;
@property (weak, nonatomic) IBOutlet UITextView *retTextView;
@property (weak, nonatomic) IBOutlet UITextField *phoneTf;
@property (weak, nonatomic) IBOutlet UITextField *nameTf;
@property (weak, nonatomic) IBOutlet UITextField *scoreTf;
@property (weak, nonatomic) IBOutlet UITextField *applyTf;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.serverUrlTf.text = baseUrl;
    self.codeTf.text = productcode;
    self.productIdTf.text = productId;
    self.idCardTf.text = testcfImg;
    self.phoneTf.text = phone1;
    self.nameTf.text = customerName1;
    self.scoreTf.text = [NSString stringWithFormat:@"%.1f",checkScore];
    self.applyTf.text = applyID;
    [[RecordManager sharedInstance] initWithServerPath:self.serverUrlTf.text delegate:self];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.label.text = @"初始化录制模块中。。";
    self.hud = hud;
}

//// 获取支持的视频编码器
//- (void)getSupportedVideoCodecs {
//    // 创建一个空的 AVAsset 对象
//    bool isSup = VTIsHardwareDecodeSupported(kCMVideoCodecType_HEVC);
//    NSLog(@"is sup = %d",isSup);
//}


- (IBAction)singalClicked:(UIButton *)sender {
    [[RecordManager sharedInstance] startRecord:self.idCardTf.text similarity:[self.similarityTf.text doubleValue] product:self.codeTf.text  navigationController:self.navigationController];

}


- (IBAction)doubleClicked:(UIButton *)sender {
    [[RecordManager sharedInstance] remote:[self.productIdTf.text intValue] customerName:self.nameTf.text phone:self.phoneTf.text frontCheckFaceScore:self.scoreTf.text applyId:self.applyTf.text navigationController:self.navigationController];
}


- (void)onInitResult:(NSString *)code message:(NSString *)message{
    NSLog(@"init code = %@ msg = %@",code,message);
    if ([code isEqual:@"0"]) {
        
    }else{
        
    }
    [self.hud hideAnimated:YES];
}

- (void)onRecordResult:(NSString *)code message:(NSString *)message filePath:(nonnull NSString *)filePath{
    NSLog(@"record code = %@ msg = %@ url = %@",code,message,filePath);
    self.retTextView.text = [NSString stringWithFormat:@"code = %@  msg = %@ \n filePath = %@",code,message,filePath];
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];

}

@end
